package com.photographysharing.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.photographysharing.dto.MenusDTO;
import com.photographysharing.dto.PhotoDTO;
import com.photographysharing.entity.Menus;
import com.photographysharing.request.SelectByPaging;
import com.photographysharing.response.DatasResponse;
import com.photographysharing.service.MenusService;
import com.photographysharing.mapper.MenusMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Z
* @description 针对表【menus】的数据库操作Service实现
* @createDate 2024-06-06 15:31:56
*/
@Service
public class MenusServiceImpl extends ServiceImpl<MenusMapper, Menus>
    implements MenusService{

    private MenusMapper menusMapper;

    public MenusServiceImpl(MenusMapper menusMapper) {
        this.menusMapper = menusMapper;
    }

    @Override
    public DatasResponse<MenusDTO> select(SelectByPaging paging) {
        try{
            int index = paging.getIndex();
            int size = paging.getSize();
            List<MenusDTO> menus = menusMapper.selectParent(0,100,"");
            int count = menusMapper.selectCount(0);
            for(MenusDTO menu : menus){
                List<MenusDTO> items = menusMapper.selectChildren(menu.getId());
                menu.setChildren(items);
            }
            return new DatasResponse<MenusDTO>(count,menus);
        }catch (Exception e ){
            return null;
        }
    }

    @Override
    public DatasResponse<MenusDTO> getMenus(String role) {
        List<MenusDTO> menus = menusMapper.selectParent(0,1000,role);
        for(MenusDTO menu : menus){
            List<MenusDTO> items = menusMapper.selectChildren(menu.getId());
            menu.setChildren(items);
        }
        return new DatasResponse<MenusDTO>(0,menus);
    }
}




